#include "stdafx.h"
#include "TestData.h"
#include "Log.h"

CTestDataSave::CTestDataSave()
{
}

CTestDataSave::~CTestDataSave()
{
}

BOOL CTestDataSave::Init()
{
	log_printf("[TOMTOM_FT] CTestDataSave::init \n");
	ClearAllData();
	return TRUE;
}

void CTestDataSave::ClearAllData()
{
	ClearVoltageData();
	ClearCurrentData();
	ClearDeviceData();
	ClearSystemInfoData();
	ClearFAUiReportData();
	ClearGPSCoolStartData();
	ClearRFWifiChannelData();
	ClearCameraFocusData();
}

void CTestDataSave::ClearVoltageData()
{
	mVoltageDataMap.clear();
	mVoltageTestData="";
}

CString CTestDataSave::AddData2Voltage(CString name, CString value)
{
	value.Replace("\r\n", "");
	map<CString, CString> ::iterator iter;

	iter = mVoltageDataMap.find(name);
	if(iter != mVoltageDataMap.end())
	{
		//Find, the value is"<<iter->second<<endl;
		mVoltageDataMap.erase(iter);
	}
	else
	{
		//Do not Find"<<endl;
	}

	mVoltageDataMap.insert(pair<CString, CString>(name, value));

	return "";
}

CString CTestDataSave::GetVoltageData()
{
#if APK_MES_SIMULATE
	return "CPU_VOL:0.9086V,GPU_VOL:0.8179V,DDR_VOL:1.2460V,EMMC_VOL:1.8119V,LCD_VOL:2.8075V,GPS_VOL:0.0097V,RTC_VOL:1.8132V,LEDA_VOL:17.2408V,PS_VOL:4.1130V,WIFI_BT_VOL:3.4506V,ADC_40_VOL:3.9410V,ADC_37_VOL:3.6360V,";
#endif

	map<CString, CString>::iterator iter;
	for(iter = mVoltageDataMap.begin(); iter != mVoltageDataMap.end(); iter++)  
	{
		mVoltageTestData = mVoltageTestData+iter->first+":"+iter->second+",";
	}

	return mVoltageTestData;
}

void CTestDataSave::ClearCurrentData()
{
	mCurrentDataMap.clear();
	mCurrentTestData="";
}

CString CTestDataSave::AddData2Current(CString name, CString value)
{
	value.Replace("\r\n", "");

	map<CString, CString> ::iterator iter;

	iter = mCurrentDataMap.find(name);
	if(iter != mCurrentDataMap.end())
	{
		//Find, the value is"<<iter->second<<endl;
		mCurrentDataMap.erase(iter);
	}
	else
	{
		//Do not Find"<<endl;
	}

	mCurrentDataMap.insert(pair<CString, CString>(name, value));

	return "";
}

CString CTestDataSave::GetCurrentData()
{
#if APK_MES_SIMULATE
	return "NORMAL_CURRENT:0.54280A,CHARGE_USB_CURRENT:0.4146A,CHARGE_WSM_CURRENT:0.4108A,NTC_HIGH_CURRENT:0.4120A,NTC_LOW_CURRENT:0.4153A,SUSPEND_CURRENT:0.00429A,POWER_OFF_CURRENT:0.00025A,";
#endif

	map<CString, CString>::iterator iter;
	for(iter = mCurrentDataMap.begin(); iter != mCurrentDataMap.end(); iter++)  
	{
		mCurrentTestData = mCurrentTestData+iter->first+":"+iter->second+",";
	}

	return mCurrentTestData;
}

void CTestDataSave::ClearDeviceData()
{
	mDeviceDataMap.clear();
	mDeviceTestData = "";
}

CString CTestDataSave::AddData2Device(CString name, CString value)
{
	value.Replace("\r\n", "");

	map<CString, CString> ::iterator iter;

	iter = mDeviceDataMap.find(name);
	if(iter != mDeviceDataMap.end())
	{
		//Find, the value is"<<iter->second<<endl;
		mDeviceDataMap.erase(iter);
	}
	else
	{
		//Do not Find"<<endl;
	}

	mDeviceDataMap.insert(pair<CString, CString>(name, value));

	return "";
}

CString CTestDataSave::GetDeviceData()
{
#if APK_MES_SIMULATE
	return "GPS_SNR:,MIC_SPK:1,USB_HOST:disconnect,WSM_HOST:1,";
#endif
	map<CString, CString>::iterator iter;
	for(iter = mDeviceDataMap.begin(); iter != mDeviceDataMap.end(); iter++)  
	{
		mDeviceTestData = mDeviceTestData+iter->first+":"+iter->second+",";
	}
	return mDeviceTestData;
}

void CTestDataSave::ClearSystemInfoData()
{
	mSystemInfoDataMap.clear();
	mSystemInfoTestData="";
}

CString CTestDataSave::AddData2SystemInfo(CString name, CString value)
{
	value.Replace("\r\n", "");

	map<CString, CString> ::iterator iter;

	iter = mSystemInfoDataMap.find(name);
	if(iter != mSystemInfoDataMap.end())
	{
		//Find, the value is"<<iter->second<<endl;
		mSystemInfoDataMap.erase(iter);
	}
	else
	{
		//Do not Find"<<endl;
	}

	mSystemInfoDataMap.insert(pair<CString, CString>(name, value));

	return "";
}

CString CTestDataSave::GetSystemInfoData()
{
#if APK_MES_SIMULATE
	return "INFO_CPU_ID:760014203880826034b,INFO_SN:1234567890123,INFO_PMU_IC: 0x51,INFO_EMMC_SIZE: 27G,INFO_WIFI_MAC: cc:b8:a8:16:0c:b1,INFO_BT_MAC: 22:22:A2:1C:9F:5F,INFO_SYS_VERSION:uranus_t1-eng 7.1.2 N2G48B 20191231 test-keys,";
#endif

	map<CString, CString>::iterator iter;
	for(iter = mSystemInfoDataMap.begin(); iter != mSystemInfoDataMap.end(); iter++)  
	{
		mSystemInfoTestData = mSystemInfoTestData+iter->first+":"+iter->second+",";
	}
	return mSystemInfoTestData;
}

void CTestDataSave::ClearFAUiReportData()
{
	mFAUiDataVector.clear();
	mFAUiReportTestData = "";
}
CString CTestDataSave::AddData2FAUiReport(CString data)
{
	data.Replace("\r\n", "");
	//data.Replace(" ", "");
	mFAUiReportTestData = mFAUiReportTestData + data+",";
	return mFAUiReportTestData;
}

CString CTestDataSave::GetFAUiReportData()
{
	return mFAUiReportTestData;
}

void CTestDataSave::ClearGPSCoolStartData()
{
	mGPSColdDataVector.clear();
	mGPSCoolStartTestData="";
}

CString CTestDataSave::AddData2GPSCoolStart(CString data)
{
	data.Replace("\r\n", "");
	//data.Replace(" ", "");
	mGPSCoolStartTestData = mGPSCoolStartTestData+data+",";
	return mGPSCoolStartTestData;
}

CString CTestDataSave::GetGPSCoolStartData()
{
	return mGPSCoolStartTestData;
}




void CTestDataSave::ClearRFWifiChannelData()
{
	mRFWifiChannelMap.clear();
}

CString CTestDataSave::AddData2RFWifiChannel(CString name, CString value)
{
	value.Replace("\r\n", "");
	map<CString, CString> ::iterator iter;

	iter = mRFWifiChannelMap.find(name);
	if(iter != mRFWifiChannelMap.end())
	{
		//Find, the value is"<<iter->second<<endl;
		mRFWifiChannelMap.erase(iter);
	}
	else
	{
		//Do not Find"<<endl;
	}

	mRFWifiChannelMap.insert(pair<CString, CString>(name, value));

	return "";
}

CString CTestDataSave::GetRFWifiChannelData()
{
	CString tempData = " ";

	map<CString, CString>::iterator iter;
	for(iter = mRFWifiChannelMap.begin(); iter != mRFWifiChannelMap.end(); iter++)  
	{
		tempData = tempData+iter->first+":"+iter->second+",";
	}

	return tempData;
}

void CTestDataSave::ClearCameraFocusData()
{
	mCameraFocusMap.clear();
}


CString CTestDataSave::AddData2CameraFocus(CString name, CString value)
{
	value.Replace("\r\n", "");
	map<CString, CString> ::iterator iter;

	iter = mCameraFocusMap.find(name);
	if(iter != mCameraFocusMap.end())
	{
		//Find, the value is"<<iter->second<<endl;
		mCameraFocusMap.erase(iter);
	}
	else
	{
		//Do not Find"<<endl;
	}

	mCameraFocusMap.insert(pair<CString, CString>(name, value));

	return "";

}


CString CTestDataSave::GetCameraFocusData()
{
	CString tempData = " ";

	map<CString, CString>::iterator iter;
	for(iter = mCameraFocusMap.begin(); iter != mCameraFocusMap.end(); iter++)  
	{
		tempData = tempData+iter->first+":"+iter->second+",";
	}

	return tempData;
}